Okay.
So today we're going to have a look at game game passes.
So there are two lessons here one on game passes and one is on developer products.
Now people often get confused between game passes and developer products.
Both you can buy and you can both set them up quite easily.
The difference is a game pass can only be purchased once this is unlocked, contents or things like
that.
The developer products you can purchase multiple times, so things like additional cash or a booster
for a certain period of time.
So make sure when you are wanting to code something like this, you're using a correct one.
If you don't use a correct one, it might mean that players can buy game passes or they like, or they
can only buy more cash once.
Which obviously, if you are looking at making Robux and actually earning some money from your game,
um, you want to make sure it's all working nice, nice and good and properly.
So we're looking today at Game Pass, where the ones you can only purchase once.
If you are interested in looking at things you can purchase multiple times.
We'll be looking at that next lesson just to clear that up.
Okay.
So um, there are two parts to this.
One part is done on the client, one part is done on the server.
The first bit is done on the client.
So we're going to add a local script into here okay.
So both of these use a service called Marketplace Service.
Basically everything in this advanced section is just services at this point.
So let's get marketplace service marketplace.
Um, one word service is equal to game get service marketplace service.
Now be careful again because marketplace service contains both Game pass functions and develop products
functions.
Just make sure you remember which one you're trying to do.
Okay.
Let's also reference a player.
So local player is equal to game dot players local player okay.
So we now need a game pass ID.
Now to make to use a game pass ID you can either use a game pass has already been made or make one yourself.
So I'm going to use a premade one here that I've got um from earlier.
But um, if you do want to know how to make a game pass yourself, it's very easy.
All you need to do is go to your game on.
So you have to publish your game.
Go find your game on the roadblocks home page.
Configure your game and you should.
It's very clear you just have a browse.
But um, there'll be a section for you to add, um, items, associated items onto your game.
And under there there'll be developer products passes, um, badges and also game passes.
I'll have a look at Game Pass and add one in there.
Just gives you some basic details like the name, um, and all that other kind of stuff.
Maybe I should probably make a lecture at some point explaining how to make these, um, yourself probably
should do that.
Maybe I will do that, yes.
But, um, so if you're not too confident, that's fine.
There will be a lecture, um, some point in this section showing you how to do that.
Um, but you can probably figure it out.
But I will show you that just in case.
Okay.
So I'm going to use this game pass ID.
And the reason I'm writing it up here is just much easier.
So don't misspelt mistype the number or anything like that.
So this has gotten over here.
63638020
okay.
Cool.
So um, how does this work?
Well, there are two parts with this.
So how a game pass works is that something triggers the player to be asked by the game pass.
That's called prompts.
Prompts prompting them to buy the game Pass.
Now once they have.
So a little guy will come up saying, would you like to buy this for 20 Robux?
Have a much it costs.
Okay, um, now, if they say yes or no or whatever, the prompts will be finished.
So then once the prompt has been finished, you want to get the feedback, come back and see.
Was it successful?
Did you actually buy or did we not buy?
And if they did buy it, then you want to run whatever code that you're wanting to do for them.
Okay.
So we're first going to control when they prompt the prompt purchase bit.
So when they actually um, when they're actually, um, trying to buy the Game Pass okay.
So we're going to make a function to this called um, prompt purchase.
Just like about here.
Okay.
So, um.
Now this is where you have to extra step that you wouldn't have to do for developer products.
So because of game passes, you only want to be able to buy them once.
Um.
You want to check to see if they already have it.
So we're going to say by default a local has pass.
Is equal to false like this here.
And we're then going to check marketplace service.
If the user already has the game pass.
And we're going to use our call that we learned in the data stores lesson for this.
Now if you've kind of been jumping back and back and forward in this section as the lesson is a bit
less structured and more so just different different areas, I would recommend watching the data stores
lesson, because quite a lot of the stuff I'm explaining is stuff that I spent a good few minutes talking
about the peak oil, so have a watch for that.
But basically the peak oil prevents a function from throwing an error if some of these services are
down.
So marketplace services is sometimes down.
So so we need to use a peak oil just to make it a bit extra safe.
So local success.
Um, I have a message.
Is equal to P call.
Function like that better.
And cool.
So we want to basically check to see if they have the pass.
And we can use a handy built in function for that called um colon user owned.
User owns Game Pass async.
Probably one of our longest ones you'll use.
That's probably longer actually, but some of the some of the functions can get quite long.
Um, but yeah.
So basically basically check to see if the user has the game pass.
It'll be true if they do, and it'll be false if they don't, which will then update our variable up
here.
So means putting the user ID which obviously is just played user ID there.
And we also need the game pass ID, which of course we have up there as well.
When you have numbers and stuff you're going to be using commonly, it's a good idea to make it a variable,
so we're not repeating it and you're not going to make any possible issues, because if you actually
mistyped this when writing it down here, it would not work entirely.
Okay.
And that's it for the pickle.
We then afterwards want to check if they have the pass.
So if they have the pass sorry if they don't have the pass actually.
So if they do have the pass you might want to put a message saying you already own this if you wanted
to.
But if you're not really too bothered about doing that, you just want to do some code.
If they don't have the game pass now, this will be basically prompting them to purchase if we don't
already have it.
Do you want to buy it?
For this, we use another built in function called Prompt Game Pass purchase.
Now don't you don't use prompt product purchase.
That's the next lesson we're looking at prompt Game Pass purchase like that there.
And this has the player which we have as the local player up here and the game pass ID which we have
written there as well.
Okay.
Um, so that's, that's the code that's going to prompt them to purchase this.
Okay.
And we then down here want to run this function.
Um, whenever basically.
So let's make this as to a button.
So a lot of games have like buttons on the side that are like things they can purchase.
Me personally, I'm not a big fan of that at all because, um, players are not going to want to play.
They play their game if half of their viewing space is just things that they can buy.
So put it in its own area that if the player doesn't want to, then they don't feel forced to purchase
these as if the players feels it's feeling forced purchase.
Um, these game passes, they're just not going to want to play your game.
Okay, um, so let's add in a screen guy and add in a text button.
Just put it up there.
I'm not going to do anything cosmetic really with it.
Um, and we're going to say is um, script dot parent, dot mouse, one button, one click, um connect
function like that's fair.
And we then want to prompt for purchase, run that function just there.
And that's everything there on the local script okay.
Anything else we're going to handle on the server.
Because if you're wanting to do things like give them an item or give them some boosters and stuff like
that, you're going to want to do that for all players, because all players have to see that item,
or all players have to see the increased cache I've just gotten from a booster, for example.
So it has to be done on the server.
So let's just make sure this works as our offer.
So let's play the game.
Not actually sure what this um, I can't remember what game pass this was.
Let's have a look.
So let's click the button.
Um.
Ah, okay.
So because this is not my game pass, I've got here that third party item sales have been disabled.
So this is something you have to enable if you do want to use it.
So if you are following along with me and using the same ID with the same ID as I am, you're going
to want to do this as well.
So go over to Game Settings and go over to security and click Allow third Party sales to be on okay.
Now please, please please, once you have finished your game and you're looking to publish it, make
sure this is turned off.
Okay.
We will look a bit more about some things you should do once you think your game is finished, but that
should be definitely one of the things you turn off.
Because when your game, when you've got a finished product, um, you don't you're not really going
to be wanting to use other people's game passes.
Now, this makes it quite vulnerable to attacks.
It said there because basically anyone can decide to, um, get the get your player to buy their game
pass and you won't get the money, they will get the money.
So you don't want that.
Let's try this again and let's take a look.
Here.
Yep.
Nice.
So it was a sword.
This one here.
Okay.
And it's just the standard thing you get when you do want to purchase this stuff.
Okay.
You can either cancel or you can buy it.
But remember it's a test purchase so your account will not be charged.
So even how much Robux it is, it's not going to be charged for that.
Let's buy it.
And of course nothing else happens.
We need to encode what to do when they do buy it.
Okay, so let's add a script into server script service and write out the rest of the code for this.
So let's copy over marketplace service and regain pass ID, making sure to get rid of player because
we don't we don't reference local players in server scripts.
Okay.
So this is a handy event we use here called Dot prompt.
Um, this one here is um, quite a long one.
It's um prompt.
Um Game Pass purchase finished their prompt game Pass purchase finished.
Okay, quite a long one.
Um, but this basically occurs when a, um, when the player has gone through and they have either pressed
cancel or they have bought it.
Now, this doesn't necessarily mean that this doesn't necessarily mean that they do.
They have succeeded and they have bought it.
It's only that they've completed the purchasing sequence.
So you do need to also make sure that they have bought it with this connectivist like we do normally.
So many parameters here.
You need the we've got the player that's given the game pass ID um, which we're going to call ID,
not game pass ID I'll show you why in a minute and was purchased.
Okay.
So we want to check two things here.
We need to check one.
But the game pass would actually purchased if they did go ahead and say that they wanted it.
This value here would be true.
Um, which is great.
So we want to just say if was purchased.
However, if you have multiple game passes, you don't only want to know if it's if it's been successful,
but that they've purchased the right one as you want to code a couple few ones, a couple different
ones.
Sorry.
You need to make sure that the game pass is the correct one that you're wanting to get.
There's no point coding a booster if they've just purchased a new area in the map, for example.
So you want to say and but the game pass ID matches up with the ID of those purchased.
Now if this was the case then you can do ops right.
Two equal signs.
Then you can do whatever code you like here.
Okay.
So let's say in this case it's going to add a part into the game.
So local new part.
Is equal to an instance dot new.
Parts into the workspace there.
Let's say new part dot position is equal to vector three.
Dot new zero 20 zero.
And let's set the and make a bold color.
So new cut a new part dot brick color is equal to brick color dot new.
Right and then set it to neon.
Oh.
Won't not dot.
Neon dot material.
Enum.
Dot material.
Dot neon.
Okay, there we go.
Some properties there that wanted to change.
So let's try this out.
So let's play the game and have a look.
So let's click the button.
Do you want to buy it?
Yes I do.
Your purge has been succeeded.
And it then adds in my parts just there.
Okay, so now obviously no one's going to want to buy it for just adding a part into the game, but
it gives a possibilities for you to do whatever you'd like with that.
Okay, so it's pretty cool.
And it gives you it gives you the option to add in some things that people can buy in your game as well,
to make some earnings from your game.
Now, if you are interested in how to make earnings from your game and things like that, I talk about
that in a later section.
So if you want to skip to that, feel free.
Um, but if you are going through this, um, in the, in the order that I set it out, then you will
get to that, I think is the last probably going to be the last one.
But we just talk a bit about, um, the best ways to go go through this and the best ways to, um,
make a bit of money from your game.
So that will be something we'll have a look at a bit more in the future.
But now you do know how to script it.
Okay.
So um, remember as well, this is only for game passes.
Developer products are very similar and bonus are probably a bit easier to code.
So we're going to have a look at those at in the next lecture.
So you're able to code both.
So um have a play around with that and join me.
The next lecture.
We have a look at the second half which are now developer products.
So I'll see you in the next lecture.